package main

import "fmt"

func max(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func main() {
	var num int
	fmt.Scan(&num)
	var vol int
	fmt.Scan(&vol)

	var f [1005]int

	for i := 0; i < num; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		for j := vol; j >= a; j-- {
			f[j] = max(f[j], f[j-a]+b)
		}
	}
	fmt.Print(f[vol])
}
